package com.min.redis.api.controller.rank;

import com.min.redis.api.base.Response;
import com.min.redis.api.base.RestBusinessTemplate;
import com.min.redis.api.manager.RankManager;
import com.min.redis.api.request.AddRequest;
import com.min.redis.api.response.RankItemResponse;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
public class RankController {

    private final RankManager rankManager;

    @GetMapping("/rank/total")
    public Response<List<RankItemResponse>> getRank(){
        return RestBusinessTemplate.execute(() -> rankManager.getRanks());
    }
    @PostMapping("/add")
    public Response<Boolean> addRank(@RequestBody AddRequest request){
        return RestBusinessTemplate.execute(()->rankManager.addScore(request.getKey()));
    }
    @GetMapping("/rank/minute")
    public Response<List<RankItemResponse>> getMinuteRank(){
        return RestBusinessTemplate.execute(()->rankManager.getMinuteRank());
    }

    @GetMapping("/rank/hour")
    public Response<List<RankItemResponse>> getHourRank(){
        return RestBusinessTemplate.execute(()->rankManager.getHourRank());
    }

}
